#include "Catalyst.h"

/*************************
BEGIN loading the XML file
**************************/
void Catalyst::LoadXmlFile(std::string path)
{
	pugi::xml_parse_result result = doc.load_file(path.c_str());
	naviNode = doc.first_child();
	std::cout<<"Catalyst FOUND"<<std::endl<<"-----------------"<<std::endl;
}
/***********************
END loading the XML file
************************/

void Catalyst::GoLower(std::string nodeName)
{
	naviNode = naviNode.child(nodeName.c_str());
	std::cout<<"Going lower to: "<<naviNode.name()<<std::endl;
}

void Catalyst::GoLower(std::string nodeName, std::string attrName, std::string attrValue)
{
	for (pugi::xml_node iter: naviNode.children(nodeName.c_str()))
	{
		if(iter.attribute(attrName.c_str()).value() == attrValue)
		{
			naviNode = iter;
		}
	}
	std::cout<<"This is the searched node: "<<naviNode.attribute(attrName.c_str()).value()<<std::endl;
}

void Catalyst::GoHigher()
{
	naviNode = naviNode.parent();
	std::cout<<"Going higher to: "<<naviNode.name()<<std::endl;
}

void Catalyst::AttrVal(std::string attrName)
{
	std::cout<<"Attribute "<<attrName<<" in "<<naviNode.name()<<" is: "<<naviNode.attribute(attrName.c_str()).value()<<std::endl;
}


/***************************************************
BEGIN importing child nodes for a given level 1 node
****************************************************/
std::list<std::string> Catalyst::GetChildren(std::string level1Node ) {
	std::list<std::string> nodes;
	int i = 0;
	for (pugi::xml_node iter: doc.first_child().child(level1Node.c_str()).children())
	{
		nodes.push_back(iter.attribute("name").value());
	}
	return nodes;
}
/*************************************************
END importing child nodes for a given level 1 node
**************************************************/